package com.woniu.job.mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.job.entity.User;
import org.springframework.stereotype.Component;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author song
 * @since 2019-12-24
 */
@Component
public interface UserMapper extends BaseMapper<User> {

	@Select("select * from user where id=#{id}")
	User findUserById(User user);
	/**
	 * 上传头像
	 * @param user
	 */
	@Update("UPDATE user SET avatar = #{avatar} WHERE id= #{id}")
	void updateAvater(User user);
	/**
	 * 修改密码
	 * @param user
	 */
	@Update("UPDATE user SET password = #{password} WHERE id= #{id}")
	void updatePwdById(User user);
	/**
	 * 修改个人信息
	 * @param user
	 */
	@Update({"<script>",
		"UPDATE user set realName =#{realName},telephone=#{telephone}",
		"<when test='gender!=null'>",
			",gender=#{gender}",
		"</when>",
		"<when test='birthdate!=null'>",
			",birthdate=#{birthdate}",
		"</when>",
		"<when test='qq!=null'>",
			",qq=#{qq}",
		"</when>",
		"<when test='address!=null'>",
			",address=#{address}",
		"</when>",
		"<when test='profile!=null'>",
			",profile=#{profile}",
		"</when>",
		"<where>",
			"id=#{id}",
		"</where>",
		"</script>"})
	void updateProfile(User user);
    /**
     * 注册
     * @param user
     * @return
     */
    @Select("select count(*) from user where account=#{account}")
    int findUserByAcc(User user);

    /**
     * 登录
     */
    @Select("select * from user where account=#{account} and password=#{password}")
    User findUserByAccAndPwd(User user);


}
